<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>订单支付</title>
    <script src="./js/jquery-3.3.1.min.js"></script>
    <script src="./js/vue.min.js"></script>
    <script src="./js/http.js"></script>
</head>
<body>

<script>

    new Vue({
        el:'app',
        data(){
            return {
                callPayParam:{
                    appId:'',
                    timeStamp:'',
                    nonceStr:'',
                    package:'',
                    signType:'RSA',
                    paySign:'',
                }
            }
        },
        methods:{
            prePay(openId,uuid){
                http.get('/?openid='+openId+'&uuid='+uuid,{},res=>{
                    //let ret = JSON.parse(res);
                    let ret = res;
                    if(ret.code == undefined){
                        this.callPayParam = ret;
                        this.onBridgeReady()//唤起支付
                    }else{
                        alert(ret.code + "," + ret.message);
                    }
                });
            },
            onBridgeReady() {
                WeixinJSBridge.invoke('getBrandWCPayRequest', {
                        "appId": this.callPayParam.appId,//公众号名称，由商户传入
                        "timeStamp": this.callPayParam.timeStamp,//时间戳，自1970年以来的秒数
                        "nonceStr": this.callPayParam.nonceStr,//随机串
                        "package": this.callPayParam.package,//预支付返回数据
                        "signType": this.callPayParam.signType,//微信签名方式：
                        "paySign":this.callPayParam.paySign //微信签名
                    },
                    function(res) {
                        if (res.err_msg == "get_brand_wcpay_request:ok") {
                            // 使用以上方式判断前端返回,微信团队郑重提示：
                            //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。

                            //window.location.href = "https://wangbin.mynatapp.cc/wxpro/redirect?index=3";
                            window.history.back(-1);
                        }
                    });
            }
        },
        mounted() {
            let openId = getQueryVariable('openid');
            let uuid = getQueryVariable('uuid');
            this.prePay(openId,uuid);
        }
    })

</script>
</body>
</html>